package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.notice.CreateNoticeFormBean;
import com.info.zhiduoduo.admin.model.formbean.notice.NoticeListFormBean;
import com.info.zhiduoduo.admin.service.NoticeService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.StatusMsg;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;

import com.info.zhiduoduo.repository.entity.notice.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/notice")
@Api(tags = "公众号公告接口")
public class NoticeController {

	@Autowired
	NoticeService noticeService;

	@ZddLog(name = "创建并发送公告")
	@PostMapping("/create")
	@ApiOperation("创建并发送公告")
	public SmartResult createNotice(@Valid @RequestBody BaseSimpleFormBean<CreateNoticeFormBean> formBean) {
		return noticeService.createNotice(formBean);
	}

	@ZddLog(name = "指定创建并发送公告")
	@PostMapping("/specifyCreate")
	@ApiOperation("指定创建并发送公告")
	public SmartResult specifyCreate(@Valid @RequestBody BaseSimpleFormBean<CreateNoticeFormBean> formBean) {
		if (null == formBean.getReqdata()) return SmartResult.fail(StatusMsg.StatusMsg_101);
		return noticeService.specifyCreate(formBean.getReqdata(),formBean.getUserid());
	}

	@PostMapping("/list")
	public SmartResult getNoticeList(@RequestBody BaseSimpleFormBean<NoticeListFormBean> formBean) {
		return noticeService.getNoticeList(formBean);
	}

	@PostMapping("/detail")
	public SmartResult getDetail(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return noticeService.getDetail(formBean);
	}

	@ZddLog(type = ZddLogType.DELETE,name = "公众号公告删除",entities = @LogEntity(entity = Notice.class,parameters =
	@LogParameter(fields = "noticeid",parameters = "formBean.reqdata")))
	@PostMapping("/del")
	public SmartResult delNotice(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return noticeService.delNotice(formBean);
	}
}
